﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace WebSpiderLib
{
    public class Utils
    {
        // Methods
        private Utils()
        {
        }

        public static byte[] ByteArrayFromStream(Stream input)
        {
            byte[] buffer3;
            Debug.Assert(input != null);
            ArrayList list = new ArrayList();
            BinaryReader reader = new BinaryReader(input);
            try
            {
                while (true)
                {
                    byte[] c = reader.ReadBytes(0x400);
                    list.AddRange(c);
                    if (c.Length != 0x400)
                    {
                        break;
                    }
                }
                if (list.Count == 0)
                {
                    return null;
                }
                byte[] array = new byte[list.Count];
                list.CopyTo(array);
                buffer3 = array;
            }
            finally
            {
                reader.Close();
            }
            return buffer3;
        }

        public static string StringFromStream(Stream input, Encoding encoding)
        {
            string str;
            Debug.Assert(input != null);
            StreamReader reader = new StreamReader(input, encoding);
            try
            {
                str = reader.ReadToEnd();
            }
            finally
            {
                reader.Close();
            }
            return str;
        }
    }
}
